#!/usr/bin/env
#

user="dbuser"
password="123456"
host="localhost"
database="school"
table="student1"

# ↓这里选择直接写,不使用变量拼接,不然会报command not found的错误
# mysql_conn="mysql -u"$user" -p"$password" -h"$host""

#Internal Field Seperator（LINUX字段分隔符）,字段分隔符,默认为tab和空格形成的空白
#设置后,会传递给read等相关命令
#注意转译
IFS="\|\|"

cat data2.txt | while read id name birth sex
do
  if [ "$id" -gt 1014 ];then
    #$mysql_conn -e "INSERT INTO $database.$table values('$id','$name','$birth','$sex')"
    mysql -u"$user" -p"$password" -h"$host" -e "INSERT INTO $database.$table values('$id','$name','$birth','$sex')"
    # $database. 就等同于 -D$database
  fi
done
